package com.shanzmoo.db.module.psys.domain.dto;

import com.alibaba.fastjson.JSON;
import com.shanzmoo.base.bean.ValidList;
import com.shanzmoo.db.module.msys.entity.MSysRoleEntity;
import com.shanzmoo.db.module.msys.entity.MSysRoleMenuEntity;
import com.shanzmoo.db.module.psys.entity.PSysRoleEntity;
import com.shanzmoo.db.module.psys.entity.PSysRoleMenuEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;

/**
 * 平台管理系统角色 保存对象
 *
 * @author Gzhao 2021-03-10
 */
@Data
@ApiModel("平台管理系统角色-保存对象")
public class RoleSaveDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @NotEmpty(message = "角色名不允许为空")
    @ApiModelProperty(value = "角色名", required = true)
    private String roleName;

    @ApiModelProperty(value = "角色权限字符串")
    private String roleKey;

    @ApiModelProperty(value = "状态：1-启用，0-禁用", required = true)
    private Boolean status;

    @ApiModelProperty(value = "描述")
    private String description;

    @NotEmpty(message = "菜单权限id不允许为空")
    @ApiModelProperty("菜单权限id列表" )
    private ValidList<Integer> menuIds;

    public MSysRoleEntity convertM() {
        return JSON.parseObject(JSON.toJSONString(this), MSysRoleEntity.class);
    }

    public PSysRoleEntity convertP() {
        return JSON.parseObject(JSON.toJSONString(this), PSysRoleEntity.class);
    }

    public static MSysRoleMenuEntity convertRoleMenuM(Integer roleId, Integer menuId) {
        MSysRoleMenuEntity roleMenuEntity = new MSysRoleMenuEntity();
        roleMenuEntity.setRoleId(roleId);
        roleMenuEntity.setMenuId(menuId);
        return roleMenuEntity;
    }

    public static PSysRoleMenuEntity convertRoleMenuP(Integer roleId, Integer menuId) {
        PSysRoleMenuEntity roleMenuEntity = new PSysRoleMenuEntity();
        roleMenuEntity.setRoleId(roleId);
        roleMenuEntity.setMenuId(menuId);
        return roleMenuEntity;
    }
}
